# $Id: PKGBUILD 88660 2013-04-21 13:06:07Z arodseth $
# Maintainer: Alexander Rødseth <rodseth@gmail.com>
# Contributor: Bartłomiej Piotrowski <barthalion@gmail.com>
# Contributor: Larry Hajali <larryhaja[at]gmail[dot]com>
# Contributor: Hubert Grzeskowiak <arch at nemesis13 dot de>

pkgname=tinyxml
pkgver=2.6.2
pkgrel=3
pkgdesc='Simple, small, C++ XML parser that can be easily integrated into other programs'
url="http://www.grinninglizard.com/tinyxml/"
arch=('x86_64' 'i686')
license=('zlib')
depends=('gcc-libs')
makedepends=('setconf')
source=("http://downloads.sourceforge.net/${pkgname}/${pkgname}_${pkgver//./_}.tar.gz"
        'entity.patch'
        "$pkgname-2.5.3-stl.patch"
        "$pkgname.pc")
sha256sums=('15bdfdcec58a7da30adc87ac2b078e4417dbe5392f3afb719f9ba6d062645593'
            'ef493209b0a51160171fd834a7ecdddd02679463b85fb89a2ea254213e47f99b'
            '3baf2c4dbc2c8f54a151dac8860113d2f549174f83ed85d552b094dfaebb52af'
            '0e37a568eaebb8f0644f148a3d3efa921ac518217e1c0de46c2859d26516bcc4')

prepare() {
  cd "$srcdir/$pkgname"

  # Fix entity encoding.
  patch -p0 -i "$srcdir"/entity.patch

  # Make TINYXML_USE_STL permanently defined in tinyxml.h
  patch -p1 -i "$srcdir"/$pkgname-2.5.3-stl.patch

  # Fix Makefile
  setconf Makefile TINYXML_USE_STL YES
  setconf Makefile RELEASE_CFLAGS "$CXXFLAGS -fPIC"
}

build() {
  cd "$srcdir/$pkgname"

  make
  g++ -fPIC "$CXXFLAGS" -shared -o "lib${pkgname}.so.0.$pkgver" \
      -Wl,-soname,"lib${pkgname}.so.0" $(ls *.o | grep -v xmltest)
}

package() {
  cd "$srcdir/$pkgname"

  install -d -m 0755 "$pkgdir"/usr/{lib,include}
  install -m 0755 "lib${pkgname}.so.0.$pkgver" "$pkgdir"/usr/lib/
  install -m 0644 "$pkgname.h" tinystr.h "$pkgdir"/usr/include
  install -Dm644 readme.txt "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
  install -Dm644 "$srcdir/$pkgname.pc" "$pkgdir/usr/lib/pkgconfig/$pkgname.pc"

  (cd "$pkgdir/usr/lib"
    ln -s "lib${pkgname}.so.0.$pkgver" "lib${pkgname}.so.0"
    ln -s "lib${pkgname}.so.0.$pkgver" "lib${pkgname}.so"
  )
}

# vim:set ts=2 sw=2 et:
